<?php
/**
 * Created by PhpStorm.
 * User: luzy
 * Date: 2018/7/5
 * Time: 下午2:09
 */

class Post_model extends Base_Model
{
    private $_postdir;
    private $_postdbdir;

    public function __construct()
    {
        parent::__construct();
    }

    public function resize($config=array())
    {
        if (!isset($config['source_image'])||empty($config['source_image'])) {
            echo 'no source image'.PHP_EOL;
            exit();
        }
        if (!isset($this->image_lib)){
            $this->load->library('image_lib');
        }
        $this->image_lib->initialize($config);
        if (!$this->image_lib->resize()){
            echo $this->image_lib->display_errors();
            exit();
        }
        $this->image_lib->clear();
    }

    public function overlay($config=array())
    {
        if (!isset($config['source_image'])||empty($config['source_image'])) {
            echo 'no source image'.PHP_EOL;
            exit();
        }
        if (!isset($this->image_lib)){
            $this->load->library('image_lib');
        }
        $this->image_lib->initialize($config);
        if (!$this->image_lib->watermark()){
            echo $this->image_lib->display_errors();
            exit();
        }
        $this->image_lib->clear();
    }

    public function crop($config=array())
    {
        if (!isset($config['source_image'])||empty($config['source_image'])) {
            echo 'no source image'.PHP_EOL;
            exit();
        }
        if (!isset($this->image_lib)){
            $this->load->library('image_lib');
        }
        $this->image_lib->initialize($config);
        if (!$this->image_lib->crop()){
            echo $this->image_lib->display_errors();
            exit();
        }
        $this->image_lib->clear();
    }
}